"""
__author__="yanwei"
__describe__="新建营销计划（第三步）"
__API__="/plan/step/:id"
"""
from tool_class.marketing_plan_steptwo import MarketingPlanSteptwo
import requests
import json
from lib.operate_excel import OperateExcel
from tool_class.get_token import GetToken
from conf.readConfig import ReadConfig
import os


class MarketingPlanStepthree():

    def marketing_plan_step_three(self):
        # 获取域名
        host = ReadConfig().get_url("test_http_url")

        # 获取计划第二步返回的计划id
        plan_id = MarketingPlanSteptwo().marketing_plan_step_two()

        # 获取token
        token = GetToken().mobile()

        # 请求参数存放地址
        case_path = os.path.join(os.path.join(os.path.dirname(os.path.split(os.path.realpath(__file__))[0]), "data"),
                                 "接口用例.xls")

        # 请求数据存放标签页
        sheet_name = "新建计划（第三步）提交审核"

        operateexcel = OperateExcel()
        data = json.loads(operateexcel.excel_all_param(case_path, sheet_name)[0][6])
        url = operateexcel.excel_all_param(case_path, sheet_name)[0][2]

        headers = {
            "content-type": json.loads(operateexcel.excel_all_param(case_path, sheet_name)[0][5])["Content-Type"],
            "authorization": token
        }
        resp = requests.post(url=host + url + str(plan_id) + "/approvals", headers=headers, json=data)
        print("第三步：", resp.json())

        return plan_id


if __name__ == "__main__":
    MarketingPlanStepthree().marketing_plan_step_three()
